import {request} from '@/utils/request'
import type {  CodeType,  Patient,  PatientList,  User, UserInfo} from '@/types/user'

/**
 * 封装/qq第三方登录
 * @param openId qq登录返回的openid
 * @param source qq(此处默认传qq)
 * @returns Promise函数
 */
export const QqThirdparty = (openId:string,source:string )=>request<User>('/login/thirdparty', 'POST', {openId,source})
/**
 * 三方登录-解除绑定
 * @param userInfo 用户信息
 * @returns Promise函数
 */
export const ThirdpartyUnbound = (userInfo:string )=>request<User>(`/unbound/${userInfo}`, 'put')
/**
 * 三方登录绑定手机号
 * @param mobile 手机号 
 * @param code 验证码 
 * @param openId  
 * @returns 
 */
export const LoginBinding = (mobile:string ,code:string,openId:string) =>request<User>('/login/binding','POST',{mobile,code,openId})
/**
 * 刷新token
 * @param grantType 
 * @param refreshToken 
 * @returns Promise函数
*/
export const RefreshTokenA =(grantType:string ,refreshToken:string)=>request<User>('/login/refreshToken', 'POST', {grantType,refreshToken})
/**
 * 手机验证码登录
 * @param mobile 手机号 
 * @param code 验证码 
 * @returns Promise函数
 */
export const MobileCodeLogin = (mobile:string ,code:string)=>request<User>('/login', 'post', {mobile,code})
/**
 * 密码登录
 * @param mobile 手机号
 * @param password 密码
 * @returns Promise函数
 */
export const LoginByPwd = (mobile:string ,password:string)=>request<User>('/login/password', 'post', {mobile,password})
/**
 * 注册
 * @param mobile 手机号 
 * @param code 验证码 
 * @param password 密码
 * @returns Promise函数
 */
export const RegisterAPI = (mobile:string,password:string,code:string)=>request<User>('/register', 'POST', {mobile,password,code})
/**
 * 登出
 * @returns 
 */
export const LogoutAPI =()=>request<User>('/logout','GET')
/**
 * 发送验证码
 * @param mobile 手机号
 * @param type 
 * @returns 
 */

export const SendMSMCode =(mobile:string,type:CodeType)=>request<User>('/code','GET',{mobile,type})
/**
 * 获取用户信息
 * @returns promise函数
 */
export const getUserInfo = () =>request<UserInfo>('/patient/myUser')
/**
 * 获取患者列表
 * @returns 
 */
export const getPatientListAPI = () => request<PatientList>('/patient/mylist')

/**
 * 添加患者
 * @param patient {Patient}
 * @returns 
 */
export const addPatient = (patient: Patient) => request('/patient/add', 'POST', patient)
/**
 * 编辑患者
 * @param patient {Patient} 里面有所有的患者信息
 * @returns 
 */
export const editPatient = (patient: Patient) => request('/patient/update', 'PUT', patient)
/**
 * 删除患者
 * @param id 患者id
 * @returns 
 */
export const delPatient = (id:string) => request(`/patient/del/${id}`,'DELETE')
/**
 * 三方登录--qq三方登录
 * @param openId qq登录返回的openid
 * @returns 
 */
export const LoginByQQ = (openId:string) => request<User>('/login/thirdparty', 'POST', {openId,source:'qq'})
/**
 * 绑定用户新-三方登录绑定手机号
 * @param mobile 手机号
 * @param code 验证码
 * @param openId qq登录返回的openid
 * @returns 
 */
export const BindMobile = (data:{mobile:string,code:string,openId:string}) => request<User>('/login/binding', 'POST', data)